package com.toroasia.funky;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.DataOutputStream;
import java.io.IOException;

public class UserExistServlet extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {

        DataOutputStream dos = new DataOutputStream(resp.getOutputStream());

        String sn = req.getParameter("sn");
        if (sn == null) {
            resp.getWriter().println(
                    "please provide sn: 456 = false, 123 = true");
            return;
        }

        resp.setHeader("Content-Type", "application/octet-stream");

        if (sn.equals("123"))
            dos.writeByte(Byte.valueOf("1"));
        else
            dos.writeByte(Byte.valueOf("0"));
    }
}
